public class Main{
    public static void main(String[] args) {
        // 按顺序依次执行
//        generateAddressSqlData(); // 执行完后注意最开始的addressId
//        generateTaskLogSqlData(); // 要先生成地址数据(为了获取地址id)
        generateTaskSql(742, 2241);
    }


    // 生成地址表数据
    public static void generateAddressSqlData() {
        // 四川农业大学(雅安校区)
        System.out.println(generateAddressSqlDataHelper(1, "老区5舍"));
        System.out.println(generateAddressSqlDataHelper(1, "老区7舍"));
        System.out.println(generateAddressSqlDataHelper(1, "老区8舍"));
        System.out.println(generateAddressSqlDataHelper(1, "二区11舍"));
        System.out.println(generateAddressSqlDataHelper(1, "二区12舍"));
        System.out.println(generateAddressSqlDataHelper(1, "二区13舍"));
        System.out.println(generateAddressSqlDataHelper(1, "二区14舍"));
        System.out.println(generateAddressSqlDataHelper(1, "二区15舍"));
        System.out.println(generateAddressSqlDataHelper(1, "二区16舍"));
        System.out.println(generateAddressSqlDataHelper(1, "二区17舍"));
        System.out.println(generateAddressSqlDataHelper(1, "三区18舍"));
        System.out.println(generateAddressSqlDataHelper(1, "三区19舍"));
        System.out.println(generateAddressSqlDataHelper(1, "三区20舍"));
        System.out.println(generateAddressSqlDataHelper(1, "三区21舍"));
        System.out.println(generateAddressSqlDataHelper(1, "三区22舍"));
        System.out.println(generateAddressSqlDataHelper(1, "研究生公寓27栋"));
        System.out.println(generateAddressSqlDataHelper(1, "研究生公寓28栋"));

        // 绵阳师范学院(磨家校区)
        System.out.println(generateAddressSqlDataHelper(2, "5栋"));
        System.out.println(generateAddressSqlDataHelper(2, "6栋"));
        System.out.println(generateAddressSqlDataHelper(2, "7栋"));
    }

    // insert into address values (default, 学校id, 楼舍, 房间号, 13, 1, 50, 当前时间);
    public static String generateAddressSqlDataHelper(Integer collegeId, String dorm) {
        StringBuilder sb = new StringBuilder("insert into address values");
        for (int h = 1; h <= 5; h++) {
            for (int i = 1; i <= 15; i++) {
                sb.append("(default, ").append(collegeId).append(", '")
                        .append(dorm).append("', ").append(h * 100 + i).append(",  13, 1, 50, '")
                        .append(new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(System.currentTimeMillis())).append("'),");
            }
        }
        sb.deleteCharAt(sb.length() - 1);
        sb.append("; ");
        return sb.toString();
    }

    // 生成送水记录数据
    public static void generateTaskLogSqlData() {
        // 四川农业大学(雅安校区)
        System.out.println(generateTaskLogSqlDataHelper(1, "老区5舍", "管理员-system", 1, "送水员A"));
        System.out.println(generateTaskLogSqlDataHelper(1, "老区7舍", "管理员-system", 1, "送水员A"));
        System.out.println(generateTaskLogSqlDataHelper(1, "老区8舍", "管理员-system", 1, "送水员A"));
        System.out.println(generateTaskLogSqlDataHelper(1, "二区11舍", "管理员-system", 1, "送水员A"));
        System.out.println(generateTaskLogSqlDataHelper(1, "二区12舍", "管理员-system", 1, "送水员A"));
        System.out.println(generateTaskLogSqlDataHelper(1, "二区13舍", "管理员-system", 1, "送水员A"));
        System.out.println(generateTaskLogSqlDataHelper(1, "二区14舍", "管理员-system", 1, "送水员A"));
        System.out.println(generateTaskLogSqlDataHelper(1, "二区15舍", "管理员-system", 1, "送水员A"));
        System.out.println(generateTaskLogSqlDataHelper(1, "二区16舍", "管理员-system", 1, "送水员A"));
        System.out.println(generateTaskLogSqlDataHelper(1, "二区17舍", "管理员-system", 1, "送水员A"));
        System.out.println(generateTaskLogSqlDataHelper(1, "三区18舍", "管理员-system", 1, "送水员A"));
        System.out.println(generateTaskLogSqlDataHelper(1, "三区19舍", "管理员-system", 1, "送水员A"));
        System.out.println(generateTaskLogSqlDataHelper(1, "三区20舍", "管理员-system", 1, "送水员A"));
        System.out.println(generateTaskLogSqlDataHelper(1, "三区21舍", "管理员-system", 1, "送水员A"));
        System.out.println(generateTaskLogSqlDataHelper(1, "三区22舍", "管理员-system", 1, "送水员A"));
        System.out.println(generateTaskLogSqlDataHelper(1, "研究生公寓27栋", "管理员-system", 1, "送水员A"));
        System.out.println(generateTaskLogSqlDataHelper(1, "研究生公寓28栋", "管理员-system", 1, "送水员A"));

        // 绵阳师范学院(磨家校区)
        System.out.println(generateTaskLogSqlDataHelper(2, "5栋", "管理员-system2", 2, "送水员B"));
        System.out.println(generateTaskLogSqlDataHelper(2, "6栋", "管理员-system2", 2, "送水员B"));
        System.out.println(generateTaskLogSqlDataHelper(2, "7栋", "管理员-system2", 2, "送水员B"));
    }

    private static Integer addressId = 742; // 注意寝室id ！！！ 必须与之前生成的所有寝室的第一个id一样且所有id递增连续

    // insert into task_log values(default, 学校id, 寝室Id, 楼舍, 房间, 现在时间, 13, 1, 1, 订水人, 送水员id, 送水员);
    public static String generateTaskLogSqlDataHelper(Integer collegeId, String dorm, String publisher, Integer workerId, String workerName) {
        StringBuilder sb = new StringBuilder("insert into task_log values");
        for (int h = 1; h <= 5; h++) {
            for (int i = 1; i <= 15; i++) {
                sb.append("(default, ").append(collegeId).append(", ").append(addressId++).append(", '")
                        .append(dorm).append("', ").append(h * 100 + i).append(", '")
                        .append(new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(System.currentTimeMillis())).append("', ")
                        .append("13,  1, 1, '").append(publisher).append("', ")
                        .append(workerId).append(", '").append(workerName).append("'),");
            }
        }
        sb.deleteCharAt(sb.length() - 1);
        sb.append("; ");
        return sb.toString();
    }

    // 生成送水任务
    // insert into task values (寝室id, 发布人, 现在时间);
    public static void generateTaskSql(Integer addressIdStart, Integer addressIdEnd) {
        String str = "insert into task values ";
        Random random = new Random();
        for (int addressId = addressIdStart; addressId <= addressIdEnd; addressId++) {
            if (random.nextInt(100) <= 70) {
                str += "(" + addressId + ", '管理员-system', '" +
                        new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(System.currentTimeMillis())
                        + "'),";
            }
        }
        str = str.substring(0, str.length() - 1) + "; ";
        System.out.println(str);
    }
}